/*
* @Author: guoyayun
* @Date:   2017-07-16 09:46:58
* @Last Modified by:   adminstrator
* @Last Modified time: 2017-08-12 21:14:03
*/

'use strict';
require('./index.css');
var _mm   = require('util/mm.js');
//通用页面头部
var header = {
	init : function(){
		this.bindEvent();
		this.onLoad();
	},
	onLoad : function(){
		//keyword存在，则回填输入框
		var keyword = _mm.getUrlParam('keyword');
		if(keyword){
			$('#search-input').val(keyword);
		}
	},
	bindEvent : function(){
		var _this = this;
		//点击搜索按钮以后，做搜索提交	
		$('#search-btn').click(function(){
			_this.searchSubmit();
		});
		//输入回车后，做搜索提交
		$('#search-input').keyup(function(e){
			//13是回车键的keycode
			if(e.keycode === 13){
				_this.searchSubmit();
			}
		})
		
	},
	//搜索的提交
	searchSubmit : function(){
		var keyword = $.trim($('#search-input').val());
		//如果提交的时候有keword，正常条状到list页
		if(keyword){
			window.location.href = './list.html?keyword=' + keyword;
		}
		// 如果keyword为空，直接返回首页
		else{
			_mm.goHome();
		}
	}
};
header.init();